import { Component } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { AuthService } from '../auth.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-signup',
  templateUrl: './signup.component.html',
  styleUrls: ['./signup.component.css']
})

export class SignupComponent {

  constructor(private authService:AuthService, private router:Router){}

  myform:any = new FormGroup(
    {
      email:new FormControl('', [Validators.required]),
      passwd:new FormControl('', [Validators.required])
    }
  )

  regisztracioFn(email:any, passwd:any):void{

    if(this.myform.valid == true)
    {
      this.authService.signUpFn(email, passwd).then(
                                                      (adat)=> {
                                                                                        console.log("Regisztráció THEN ága.");
                                                                                        window.alert("Regisztráció megtörtént. Átirányítás...");
                                                                                        setTimeout( ():void=>{ this.router.navigate(['emailver']); }, 1000);
                                                                                        
                                                                                      }
                                                  );
    }
    else
    {
        console.log("Érvénytelen bevitel.");
        window.alert("Érvénytelen bevitel.");
    }

  }

}
